package java_0500_collection;

import java.util.HashSet;
import java.util.Objects;

@SuppressWarnings({"all"})
public class HashSetExercise02 {
    public static void main(String[] args) {
        HashSet hashSet = new HashSet();
        hashSet.add(new Employee("jack", 1200, new MyBirthday(2000, 1, 1)));
        hashSet.add(new Employee("jack", 1200, new MyBirthday(2000, 1, 1)));
        System.out.println(hashSet);
        //[Employee{name='jack', sal=1200.0, myBirthday=MyBirthday{year=2000, month=1, date=1}}]


    }
}

class Employee {
    private String name;
    private double sal;
    MyBirthday myBirthday;

    public Employee(String name, double sal, MyBirthday myBirthday) {
        this.name = name;
        this.sal = sal;
        this.myBirthday = myBirthday;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        Employee employee = (Employee) o;
        return Double.compare(employee.sal, sal) == 0 && Objects.equals(name, employee.name) && Objects.equals(myBirthday, employee.myBirthday);
    }

    @Override
    public int hashCode() {
        return Objects.hash(name, sal, myBirthday);
    }

    @Override
    public String toString() {
        return "Employee{" +
                "name='" + name + '\'' +
                ", sal=" + sal +
                ", myBirthday=" + myBirthday +
                '}';
    }
}

class MyBirthday {
    private int year;
    private int month;
    private int date;

    public MyBirthday(int year, int month, int date) {
        this.year = year;
        this.month = month;
        this.date = date;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        MyBirthday that = (MyBirthday) o;
        return year == that.year && month == that.month && date == that.date;
    }

    @Override
    public int hashCode() {
        return Objects.hash(year, month, date);
    }

    @Override
    public String
    toString() {
        return "MyBirthday{" +
                "year=" + year +
                ", month=" + month +
                ", date=" + date +
                '}';
    }
}
